#include "LogLuv.fxh"

float4x4 World;
float4x4 View;
float4x4 Projection;

float3 AmbientColor = float3(0.1, 0.15, 0.25);
float AmbientIntensity = 0;

float AmbientDiffuseIntensity = 0.3f;

shared float3 Light1Direction = normalize(float3(1, -1, -2));
shared float3 Light1Color = float3(0.9, 0.8, 0.7);

float3 DiffuseColor;
float3 EmissiveColor;

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float3 Normal : NORMAL0;
    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;

    float4 Color : COLOR0;
    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    float4 color = float4(DiffuseColor, 1);
    input.Normal = normalize(mul(input.Normal, World));

    float3 light1 = max(dot(input.Normal, Light1Direction), 0) * Light1Color;
    float3 Light = AmbientDiffuseIntensity + light1;
    output.Color = float4(AmbientIntensity * AmbientColor, 0) + color * float4(Light, 1) + float4(EmissiveColor, 1);

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input, uniform bool logluv) : COLOR0
{
	float4 returnColor = input.Color;
	if(logluv) return LogLuvEncode(returnColor.rgb);
	else return returnColor;
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction(false);
    }
}

technique Technique1Logluv
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction(true);
    }
}
